/*Copyright (C) 2009  John Zarb

    This program is free software: you can redistribute it and/or modify

    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,

    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License

    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * */
package simpleimageviewer;

import java.awt.BorderLayout;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

public class Application extends JFrame {
    
    private JLabel imageLabel;
    
    private ImageData imageData;
    
    public Application() {
        initComponents();
    }
    
    public void setCommandLineArguments(String[] args){
        if(args != null && args.length>0){
            String imagePath = args[0];
            setImageData(new ImageData(imagePath));
        }
        else
        {
            JFileChooser myFileChoser = new JFileChooser();
            myFileChoser.showOpenDialog(null);
            File imageFile = myFileChoser.getSelectedFile();
            setImageData(new ImageData(imageFile.getPath()));
        }
    }
    
    private void initComponents(){
        imageLabel = new JLabel();
        imageLabel.setHorizontalAlignment(JLabel.CENTER);
        imageLabel.setVerticalAlignment(JLabel.CENTER);
        add(new JScrollPane(imageLabel), BorderLayout.CENTER);
    }

    public void setImageData(ImageData imageData) {
        this.imageData = imageData;
        updateImageDataUI();
    }
    
    private void updateImageDataUI(){
        setTitle( imageData.getImageName() );
        imageLabel.setIcon( imageData.getImageIcon() );
    }
    
}
